<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="ExifTags"
                  targetNamespace="http://codeplex.com/DTools/ISOLanguages"
                  elementFormDefault="qualified"
                  xmlns="http://codeplex.com/DTools/ISOLanguages"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  xmlns:ISO="http://codeplex.com/DTools/ISOLanguages"
           >
    <xs:annotation>
        <xs:documentation>This XML schema defines structure of file used to generate classes and enums to work with ISO language codes. This schema is designed for private use when developing this project only.</xs:documentation>
    </xs:annotation>
    <xs:simpleType name="code2">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z][a-z]"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="code3">
        <xs:restriction base="xs:string">
            <xs:pattern value="[a-z][a-z][a-z]"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="LangName">
        <xs:restriction base="xs:token">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
    
    <!--Flags-->
    <xs:simpleType name="flag">
        <xs:restriction base="xs:string">
            <xs:enumeration value="spoken">
                <xs:annotation>
                    <xs:documentation>Marks language as spoken (currently in use, not extinct)</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="extinct">
                <xs:annotation>
                    <xs:documentation>Marks language as formerly spoken, but now dead (extinct)</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="historic">
                <xs:annotation>
                    <xs:documentation>Marks language as historic variant of current language</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="artificial">
                <xs:annotation>
                    <xs:documentation>Marks language as artificial</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="group">
                <xs:annotation>
                    <xs:documentation>Marks item as group of languages - not one distinct langauge that can be spoken</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="special">
                <xs:annotation>
                    <xs:documentation>Marks item as special language code with no language meaning</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
            <xs:enumeration value="reserved">
                <xs:annotation>
                    <xs:documentation>Marks language code as reserved for local use (applies to codes qaa-qtz, those codes are not listed)</xs:documentation>
                </xs:annotation>
            </xs:enumeration>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="scale">
        <xs:restriction base="xs:unsignedLong">
            <xs:pattern value="\d{1,3}0*"></xs:pattern>
        </xs:restriction>
    </xs:simpleType>
        
    <xs:element name="lng">
        <xs:annotation>
            <xs:documentation>Represents one language entry</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="ISO639-1" type="code2" use="optional">
                <xs:annotation>
                    <xs:documentation>Language code according to ISO 639-1</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="ISO639-2" type="code3" use="required">
                <xs:annotation>
                    <xs:documentation>Language code according to ISO 639-2</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="English" type="LangName" use="required">
                <xs:annotation>
                    <xs:documentation>Language name in English</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="Native" type="LangName" use="required">
                <xs:annotation>
                    <xs:documentation>Language name in itself (if native name is not available English is provided)</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="flag" type="flag" use="required">
                <xs:annotation>
                    <xs:documentation>Language state oif this language</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="scale" use="optional" type="scale">
                <xs:annotation>
                    <xs:documentation>Very approximate number of speakers of language. 3 meaningfull digits maximally. Not provided for groups and languages without speakers as well as for special and reserved codes.</xs:documentation>
                </xs:annotation>
            </xs:attribute> 
        </xs:complexType>
    </xs:element>
    <xs:element name="Root">
        <xs:annotation>
            <xs:documentation>Root element that contain list of laguage entries</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence minOccurs="1" maxOccurs="1">
                <xs:choice minOccurs="1" maxOccurs="unbounded">
                    <xs:element ref="lng"/>
                    <xs:element name="duplicate">
                        <xs:annotation>
                            <xs:documentation>Defines code duplicit to another</xs:documentation>
                        </xs:annotation>
                        <xs:complexType>
                            <xs:attribute name="of" type="code3">
                                <xs:annotation>
                                    <xs:documentation>Code which's this code is duplicate</xs:documentation>
                                </xs:annotation>
                            </xs:attribute>
                            <xs:attribute name="ISO639-2" type="code3">
                                <xs:annotation>
                                    <xs:documentation>Duplicate language code</xs:documentation>
                                </xs:annotation>
                            </xs:attribute>
                        </xs:complexType>
                    </xs:element>
                </xs:choice>
            </xs:sequence>
            <xs:attribute name="transformer" type="xs:string" use="required">
                <xs:annotation>
                    <xs:documentation>Addres or name of XSLT file used to generate code from this XML</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="Stage" use="required">
                <xs:annotation>
                    <xs:documentation>Stage of dicumment used for conditiona compilation</xs:documentation>
                </xs:annotation>
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="Nightly">
                            <xs:annotation>
                                <xs:documentation>Generated code is in Nightly stage</xs:documentation>
                            </xs:annotation>
                        </xs:enumeration>
                        <xs:enumeration value="Alpha">
                            <xs:annotation>
                                <xs:documentation>Generated code is in Alpha stage</xs:documentation>
                            </xs:annotation>
                        </xs:enumeration>
                        <xs:enumeration value="Beta">
                            <xs:annotation>
                                <xs:documentation>Generated code is in Beta stage</xs:documentation>
                            </xs:annotation>
                        </xs:enumeration>
                        <xs:enumeration value="RC">
                            <xs:annotation>
                                <xs:documentation>Generated code is in Release Candidate stage</xs:documentation>
                            </xs:annotation>
                        </xs:enumeration>
                        <xs:enumeration value="Release">
                            <xs:annotation>
                                <xs:documentation>Generated code is in Release stage</xs:documentation>
                            </xs:annotation>
                        </xs:enumeration>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
        <!--Constraints-->
        <xs:unique name="ISO639-1">
            <xs:annotation>
                <xs:documentation>ISO 639-1 code must be unique</xs:documentation>
            </xs:annotation>
            <xs:selector xpath="ISO:lng"/>
            <xs:field xpath="@ISO639-1"/>
        </xs:unique>
        <xs:key name="ISO639-2">
            <xs:annotation>
                <xs:documentation>ISO639-2 of &lt;lng> is key that &lt;duplicate>s reffers to</xs:documentation>
            </xs:annotation>
            <xs:selector xpath="ISO:lng"/>
            <xs:field xpath="@ISO639-2"/>
        </xs:key>
        <xs:unique name="ISO639-2_unq">
            <xs:annotation>
                <xs:documentation>ISO 639-2 code must be unique</xs:documentation>
            </xs:annotation>
            <xs:selector xpath="ISO:lng|ISO:duplicate"/>
            <xs:field xpath="@ISO369-2"/>
        </xs:unique>
        <xs:keyref name="duplicate" refer="ISO639-2">
            <xs:annotation>
                <xs:documentation>Attribute of of &lt;duplicate> must point to attribute ISO639-2 of &lt;lng></xs:documentation>
            </xs:annotation>
            <xs:selector xpath="ISO:duplicate"/>
            <xs:field xpath="@of"/>
        </xs:keyref>
    </xs:element>
</xs:schema>